import requests
from paddleocr import PaddleOCR, draw_ocr

# url = "https://fanqienovel.com/api/author/library/book_list/v0/?page_count=18&page_index=0&gender=-1&category_id=-1&creation_status=-1&word_count=-1&book_type=-1&sort=0&msToken=iiFlWbph30qLaM7zCuuEkHjeGnLVfBiplD2AWhyDwEhpjxFR4b-zZcYoGh3Id_A-tVCRYFU8YiwZs7xx2EG4H8hs-mjWdJ-tYWdXNjK2ELcxULiOCR3x_5oIWYp0GQ%3D%3D&a_bogus=xv4mXOg8Msm1Hf3h77kz9JzmeZg0YW-YgZEz1KGLq0wy"
# res = requests.get(url)
# map_dict = {
#     58383: '呢',
#     58686: '条',
#     58346: '十',
#     58632: '日',
#     58382: '我',
#     58454: '是',
#     58641: '不',
#     58423: '神',
# }
# res = res.json()
# for data in res['data']['book_list']:
#     # print(data['book_name'])
#     new_name = ""
#     for c in data['book_name']:
#         # print(c, ord(c))
#         if ord(c) in map_dict:
#             new_name += map_dict[ord(c)]
#         else:
#             new_name += c
#     print(new_name)

ocr = PaddleOCR(use_angle_cls=True, lang="ch")
img_path = "../../datas/image文字加密/58344.png"
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
    res = result[idx]
    for line in res:
        print(line, "===")

from PIL import Image

result = result[0]
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='./simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
